/*
 * Copyright (C) 2017 The MoonLake Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package com.minecraft.moonlake.legendaryweaponrel.weapons.tool;

import com.minecraft.moonlake.legendaryweaponrel.weapons.WeaponAbstractEntityDamageByEntity;
import com.minecraft.moonlake.manager.RandomManager;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

public class Gamble extends WeaponAbstractEntityDamageByEntity {

    public Gamble() {
        super("gamble", "&b赌博", Material.STONE_SWORD);
    }

    @Override
    public String[] getLore() {
        return new String[] {
                "&7几率 &a25% &7使目标受到 &c3&7-&c5 ❤ &7伤害!",
                "&7几率 &a75% &7使自身受到 &c1.5&7-&c2.5 ❤ &7伤害!"
        };
    }

    @Override
    protected void onDamage(EntityDamageByEntityEvent event, Player player, LivingEntity entity) {
        int value = (int) (Math.random() * 100);
        int chance = value <= 25 ? 1 : 0; // 几率 25 目标, 否则自身

        if(chance == 0) {
            // 自身
            int dmg = RandomManager.nextInt(3, 5); // 1.5-2.5 ❤ 就是 3-5伤害
            player.damage(dmg);
            player.playSound(player.getLocation(), Sound.HURT_FLESH, 10f, 5f);
        } else {
            // 目标
            int dmg = RandomManager.nextInt(6, 10); // 3-5 ❤ 就是 6-10 伤害
            if(entity.getHealth() <= dmg) entity.setHealth(0d); // 生命小于伤害则直接杀死
            else entity.setHealth(entity.getHealth() - dmg); // 否则当前生命减去伤害
        }
    }
}
